package com.maxmlr.mybatisplus.song.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maxmlr.mybatisplus.common.base.BaseController;
import com.maxmlr.mybatisplus.common.resut.ResultBean;
import com.maxmlr.mybatisplus.common.resut.ResultPageBean;
import com.maxmlr.mybatisplus.common.util.DateUtil;
import com.maxmlr.mybatisplus.song.entity.Song;
import com.maxmlr.mybatisplus.song.service.SongService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Package com.maxmlr.mybatisplus.song.controller
 * @ClassName SongController
 * @Description Song 控制器
 * @author max
 * @since 2019-05-11
 * @version 1.0
 * @Copyright Copyright (c) 2018: www.maxmlr.com.
 */
@RestController
@Api(value="/song", description="Song 控制器")
@RequestMapping("/song")
public class SongController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(SongController.class);

    @Autowired
    public SongService songService;

    /**
     * @Title SongController
     * @Description 获取分页列表
     * @author max
     * @since 2019-05-11
     */
    @RequestMapping("/getSongList")
    @ApiOperation(value="/getSongList", notes="获取分页列表")
    public ResultPageBean getSongList(@ApiParam(name="Song",value="Song 实体类")Song param ,
                                      @ApiParam(name="pageSize",value="页大小",required=true,defaultValue = "10")Integer pageSize,
                                      @ApiParam(name="pageNum",value="页数",required=true,defaultValue = "1")Integer pageNum) {
        ResultPageBean pageBean=new ResultPageBean();
        if(param.getBeginDate() == null) {
            if (param.getEndDate() == null) {
                param.setBeginDate(DateUtil.getMonthFirstDay());
            } else { param.setBeginDate(DateUtil.getMonthFirstDay()); }
        }
        if(param.getEndDate() == null) {
            param.setEndDate(DateUtil.getMonthLastDay());
        }
        Page<Song> page=new Page<Song>(pageNum,pageSize);
        songService.selectPageWithParam(page, param);
        pageBean.setPage(page);
        return pageBean;
    }

    /**
     * @Title SongController
     * @Description 通过id获取Song
     * @author max
     * @since 2019-05-11
     */
    @RequestMapping("/getSongById")
    @ApiOperation(value="/getSongById", notes="通过id获取Song")
    public ResultBean getSongById(@ApiParam(name="id",value="SongID",required=true)Long id) {
        ResultBean bean = new ResultBean();
        Song param= songService.selectOneByObj(id);
        bean.setData(param);
        return bean;
    }

    /**
     * @Title SongController
     * @Description 通过id删除Song
     * @author max
     * @since 2019-05-11
     */
    @RequestMapping("/deleteSongById")
    @ApiOperation(value="/deleteSongById", notes="通过id删除Song")
    public ResultBean deleteSongById(@ApiParam(name="id",value="SongID",required=true)Long id) {
        ResultBean bean = new ResultBean();
        songService.deleteById(id);
        return bean;
    }

    /**
     * @Title SongController
     * @Description 通过id更新Song
     * @author max
     * @since 2019-05-11
     */
    @RequestMapping("/updateSongById")
    @ApiOperation(value="/updateSongById", notes="通过id更新Song")
    public ResultBean updateSongById(@ApiParam(name="Song",value="Song 实体类")Song param) {
        ResultBean bean = new ResultBean();
        songService.updateById(param);
        return bean;
    }

	/**
     * @Title SongController
     * @Description 添加Song
     * @author max
     * @since 2019-05-11
     */
	@RequestMapping("/addSong")
    @ApiOperation(value="/addSong", notes="添加Song")
    public ResultBean addSong(@ApiParam(name="Song",value="Song 实体类")Song param) {
        ResultBean bean = new ResultBean();
        songService.insert(param);
        return bean;
    }
}
